package org.tema.entities;

import java.io.Serializable;
import java.lang.String;
import javax.persistence.*;

import java.util.*;

/**
 * Entity implementation class for Entity: Product
 *
 */

@Entity
@Table(name="PRODUCT")
public class Product implements Serializable {

	
	private int id;
	private String name;
	private String description;
	private String version;
	private static final long serialVersionUID = 1L;
	
	
	/* Add relational properties for TestSpecification, Testers, TestCases, TestPlans;
	   Reports relationship has been removed because the report is per TestPlan run, Specification
	   if a report's generated for a product not clear for what run an what specification.
	   Appropriate searches need to be added at business layer.
	*/
	
	
	protected Set<TestSpecification> testSpecificationSet;
	protected Set<User> user;
	protected Set<TestCase> testCaseSet;
	protected Set<TestPlan> planSet;
	
	protected User creator;
	protected User modifier;
	//////////////

	public Product() {
		super();
	} 
	
	@Id    
	@GeneratedValue
	@Column(name="ID")
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}  
	
	@Column(name="NAME")
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}   
	
	@Column(name="DESCRIPTION")
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}   
	
	@Column(name="VERSION")
	public String getVersion() {
		return this.version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	//properties accessors
	
	@OneToMany(  mappedBy="product" )
	public Set<TestSpecification> getTestSpecificationSet() {
		return testSpecificationSet;
	}

	public void setTestSpecificationSet(Set<TestSpecification> testSpecificationSet) {
		this.testSpecificationSet = testSpecificationSet;
	}

	@ManyToMany( cascade= {CascadeType.PERSIST, CascadeType.MERGE } )
	@JoinTable(name="USER_PRODUCT")
	public Set<User> getUser() {
		return user;
	}

	public void setUser(Set<User> user) {
		this.user = user;
	}

	@OneToMany( cascade= {CascadeType.PERSIST, CascadeType.MERGE }, mappedBy="product" )
	public Set<TestCase> getTestCaseSet() {
		return testCaseSet;
	}

	public void setTestCaseSet(Set<TestCase> testCaseSet) {
		this.testCaseSet = testCaseSet;
	}

	@OneToMany( cascade= {CascadeType.PERSIST, CascadeType.MERGE }, mappedBy="product" )
	public Set<TestPlan> getPlanSet() {
		return planSet;
	}

	public void setPlanSet(Set<TestPlan> planSet) {
		this.planSet = planSet;
	}

	@ManyToOne ( cascade= {CascadeType.PERSIST, CascadeType.MERGE } ,optional = false )
	@JoinColumn(name="CREATOR_ID", referencedColumnName = "ID")
	public User getCreator() {
		return creator;
	}
	
	
	public void setCreator(User creator) {
		this.creator = creator;
	}

	@ManyToOne( cascade= {CascadeType.PERSIST, CascadeType.MERGE } )
	@JoinColumn(name="MODIFIER_ID", referencedColumnName = "ID")
	public User getModifier() {
		return modifier;
	}

	public void setModifier(User modifier) {
		this.modifier = modifier;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Product other = (Product) obj;
		if (id != other.id)
			return false;
		return true;
	}
	
}// class Product
